<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'selectuser.jsp' starting page</title>

		<script type="text/javascript"
			src="<%=path%>/commonjs/jquery-1.7.1.js">
</script>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<style type="text/css">
td {
	border: 1px solid black;
}
</style>
	</head>

	<body>
		<table>

			<thead>
				全部用户如下：
				<tr>
					<td>
						id
					</td>
					<td>
						用户名
					</td>
					<td>
						密码
					</td>
					<td>
						电话号码
					</td>
					<td>
						角色
					</td>
					<td>
						用户状态
					</td>
					<td>
						操作
					</td>
				</tr>

			</thead>
			<tbody id="userinfo" style="border: 1px solid;">
			</tbody>
		</table>
		
		<script type="text/javascript">
			//调用方法getData
			getData();
			function lock(userid) {
				
				$.post('<%=path%>/json/lockUser.action', 
					{userId:userid,lockType:'YES'}, 
					function(data) {
						alert(data.result);
						$("#userinfo").html("");
						getData();
					},
					'json');
			}
			function unlock(userid) {
				$.post('<%=path%>/json/lockUser.action', 
					{userId:userid,lockType:'NO'}, 
					function(data) {
						alert(data.result);
						$("#userinfo").html("");
						getData();
					},
					'json');
			}
			function submitChange() {
				var userId = $("#userId").val();
				var password1 = $("#password1").val();
			
				var password2 = $("#password2").val();
				var telephone = $("#telephone").val();
				$.post('<%=path%>/json/modifyPersonalInfo.action', {
					userId : userId,
					password : password1,
					password1 : password2,
					telephone : telephone
				}, function(data) {
					alert(data.result);
				}, 'json');
				$("#div_nodisplay").hide();
			}
			function getData(){
				$.post('<%=path%>/json/selectuser.action', {}, function(data) {
				for ( var i = 0; i < data.users.length; i++) {
					var result = '<tr><td>' + data.users[i].id
							+ "&nbsp;&nbsp;&nbsp;</td><td>" + data.users[i].username
							+ "&nbsp;&nbsp;&nbsp;</td><td>" + data.users[i].password
							+ "&nbsp;&nbsp;&nbsp;</td><td>" + data.users[i].telephone
							+ "&nbsp;&nbsp;&nbsp;</td>" ;
					if(data.users[i].login=='1'){
						result = result	+ '<td>管理员</td>';
					}else{
						result = result	+ '<td>普通用户</td>';
					}
							
					if(data.users[i].lock=='YES'){
						result = result	+ '<td>锁定</td>';
					}else{
						result = result	+ '<td>激活</td>';		
					}
							
						result=result+	"<td>";
					if(data.users[i].lock=='YES'){
						result = result
							+ '<input type="button"  value="解除锁定" onclick="unlock('
							+ data.users[i].id + ');"/>&nbsp;&nbsp;';
					}else{
						result = result
							+ '<input type="button"  value="锁定" onclick="lock(' 
							+ data.users[i].id + ');"/>&nbsp;&nbsp;';
					}
					
					result = result + '</td></tr>';
					$(result).appendTo("#userinfo");
				}
			}, 'json');
			}
		</script>

	</body>
</html>
